package com.woniuxy01;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author 作者
 * @create 2025-09-01 12:09
 */
public class Test07 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("输入人数");
        int personCount = sc.nextInt();
        System.out.println("输入倒霉数字");
        int unluckyNum = sc.nextInt();
        int count = 0;
        int index=-1;
        boolean[] persons = new boolean[personCount];
        for (int i = 0; i < personCount; i++) {
            persons[i] = true;
        }
        System.out.println(Arrays.toString(persons));
        //循环多轮报数
        while (true) {
            //一轮报数
            for (int i = 0; i < persons.length; i++) {
                if (persons[i]) {
                    //没有被淘汰报数
                    count++;
                    //报完数以后，判断是否要被淘汰
                    if (count % unluckyNum == 0) {
                        persons[i] = false;
                        personCount--;
                    }
                }
            }
            //剩一个人，结束
            if (personCount == 1) {
                break;
            }
        }
        //显示幸存者
        for (int i = 0; i < persons.length; i++) {
            if (persons[i]) {
                index = i;
                break;
            }
        }

        System.out.println(Arrays.toString(persons));
        System.out.println(index);
    }
}
